<template>
	<view class="container">
		<mescroll-uni :down="downOption" @down="downCallback" @up="upCallback">	
			<view class="product-list">
				<!--商品列表-->
				<view class="pro-item" v-for="(item,index) in product_list" :key="index"  @tap="product_detail" :data-index="index">
					<image :src="item.image_url" class="pro-img" mode="widthFix" />
					<view class="pro-content">
						<view class="pro-tit">{{item.name}}</view>
						<view>
							<view class="pro-price">
								<text class="sale-price">￥{{item.money}}</text>
								<text class="factory-price">￥{{item.bazaar_money}}</text>
							</view>
							<view class="pro-pay">{{item.sales}}人付款</view>
							<view class="tui-badge" v-if="item.status==0"></view>
						</view>
					</view>
				</view>
				<!--商品列表-->
			</view>
		</mescroll-uni>		
	</view>
</template>

<script>
	import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue";
	import MyCollect from './my_collect-model.js'   
	var my_collect = new MyCollect();  
	export default {
		components: {
			MescrollUni
		},
		data() {
			return {
				//商品页码
				page:1,
				//商品列表
				product_list:[],
				downOption: {},
				total:0
			}
		},
		onShow: function(options) {
			this.product();
		},
		methods: {
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				try{
					var that = this;
					that.page = 1;
				} catch (e) {
					mescroll.endErr();
				}
				mescroll.resetUpScroll();
			},
			/*上拉加载的回调: mescroll携带page的参数, 其中num:当前页 从1开始, size:每页数据条数,默认10 */
			upCallback(mescroll) {
					var that = this;
					that.product((res)=>{
						mescroll.endBySize(res.data.length, res.total);
					})
			},
			//商品列表
			product(callback){
				var that = this;
				my_collect.my_collect(that.page,(res)=>{	
					if(res.code == 8888){
						if(res.data.current_page == 1){
							that.product_list = res.data.data;
							that.total = res.data.total;
						}else{
							for(var i=0;i<res.data.data.length;i++){
								that.product_list.push(res.data.data[i]);
							}
						}
					}
					if(callback){
						if(that.page < res.data.last_page){
							that.page = that.page + 1;
						}
						callback(res.data);
					}
				});
			},
			//跳转商品详情
			product_detail(e){ 
				var that = this;	
				var index = my_collect.get_data_set(e,'index');
				if(that.product_list[index].status == 0){
					var id = that.product_list[index].id;
					my_collect.my_collect_look(id,(res)=>{
						if(res.code == 8888){
							var product_id = that.product_list[index].product_id;
							my_collect.navigate_to('../product_detail/product_detail?id='+product_id);
						}
					})
				}else{
					var product_id = that.product_list[index].product_id;
					my_collect.navigate_to('../product_detail/product_detail?id='+product_id);
				}
			}
		}
	}
</script>

<style>
	@import url("my_collect.css");
</style>
